package com.nbjtjc.safe.activiti.listener;

import com.alibaba.druid.pool.DruidDataSource;
import com.nbjtjc.safe.mapper.emg.EmgPlanPublicMapper;
import com.nbjtjc.safe.util.SpringContextUtils;
import org.activiti.engine.delegate.DelegateExecution;
import org.activiti.engine.delegate.ExecutionListener;
import org.activiti.engine.delegate.JavaDelegate;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

/**
 * @auther guqianbin
 * @date 2018/5/30 15:25
 **/
@Component("processListener")
public class ProcessListener implements ExecutionListener ,JavaDelegate {
    @Value("${emgPlanPublic.finishValue}")
    private Integer finishValue;

    @Override
    public void notify(DelegateExecution delegateExecution) {
        DruidDataSource druidDataSource = SpringContextUtils.getBean(DruidDataSource.class);
        System.out.println(delegateExecution.getVariable("busKey"));
        EmgPlanPublicMapper emgPlanPublicMapper = SpringContextUtils.getBean(EmgPlanPublicMapper.class);
        if ("end".equals(delegateExecution.getEventName())) {
            Integer planPublicId = (Integer) delegateExecution.getVariable("busKey");
            emgPlanPublicMapper.updateStatus(planPublicId,finishValue);
        }
    }

    @Override
    public void execute(DelegateExecution delegateExecution) {
        DruidDataSource druidDataSource = SpringContextUtils.getBean(DruidDataSource.class);
        System.out.println(delegateExecution.getVariable("busKey"));
        EmgPlanPublicMapper emgPlanPublicMapper = SpringContextUtils.getBean(EmgPlanPublicMapper.class);
        if ("end".equals(delegateExecution.getEventName())) {
            Integer planPublicId = (Integer) delegateExecution.getVariable("busKey");
            emgPlanPublicMapper.updateStatus(planPublicId,finishValue);
        }
    }
}
